package com.feng.service;

import com.feng.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Service
public class UUIDService {
    @Autowired
    RedisService redisService;

    public <T> T getTFromRedis(HttpServletRequest request) {
        String uuid = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("uuid")) {
                uuid = cookie.getValue();
            }
        }
        Object o = redisService.get(uuid);
        T t = (T) o;
        return t;
    }
}